package org.t2.simulator;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.SSLException;

import org.gaming.protobuf3.simulator.SimulatorMain;
import org.gaming.protobuf3.simulator.netty.NettyHandler;
import org.gaming.simulator.netty.LinkType;
import org.gaming.simulator.netty.datagram.ByteDatagramClientChannelInitializer;
import org.gaming.simulator.netty.websocket.WebSocketClientChannelInitializer;
import org.gaming.simulator.simulator.panel.ConnectNorthPanel;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import pb.t2.protobuf.Wrapper.MessageWrapper;
import pb.t2.protobuf.player.Player.HeartBeatResponse;

/**
 * @auther YY
 * 
 */
public class T2Simulator {

	public static void main(String[] args) {
		System.out.println(MessageWrapper.class.getResource("."));
		String path = MessageWrapper.class.getResource(".").getPath();
		
		ProtoFileReader.readProtoFiles(path);
		
		Map<LinkType, ChannelInitializer<Channel>> channelInitializerMap = new HashMap<>();
		channelInitializerMap.put(LinkType.Tcp, new ByteDatagramClientChannelInitializer(new NettyHandler()));
		channelInitializerMap.put(LinkType.Ws, new WebSocketClientChannelInitializer(new NettyHandler()));
		try {
			SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
			channelInitializerMap.put(LinkType.Wss, new WebSocketClientChannelInitializer(sslContext, new NettyHandler()));
		} catch (SSLException e) {
			e.printStackTrace();
		}
		
		NettyHandler.addIgnoreClass(HeartBeatResponse.class);
		
		String projectDir = System.getProperty("user.dir");
		String useLogPath = projectDir + File.separator + "uselog\\silmuselog";
		ConnectNorthPanel.DEFAULT_LINK_TYPE = LinkType.Ws;
		SimulatorMain.start("游戏服连接器", new T2Logic(), channelInitializerMap, useLogPath);
	}
}
